package net.jeeshop.web.action.front;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author Jerry.hu
 * @summary
 * @Copyright (c) 2016, Lianjia Group All Rights Reserved.
 * @Description To change this template use File | Settings | File Templates.
 * @since 2016-07-14 11:07
 */
public class IndexAction extends ActionSupport {

    private String preURL;

    public String getPreURL() {
        return preURL;
    }

    public String index(){

        return "index";
    }

    @Override
    public String execute () throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        String lang = request.getParameter("request_locale");
        Locale locale = (Locale) ActionContext.getContext().getSession().get("WW-TRANS-I18N-LOCALE");
        if ("en".equals(lang)) {
            ActionContext.getContext().setLocale(Locale.US);
            ActionContext.getContext().getSession().put("WW-TRANS-I18N-LOCALE", Locale.US);
        } else if("zh".equals(lang)){
            ActionContext.getContext().setLocale(Locale.CHINESE);
            ActionContext.getContext().getSession().put("WW-TRANS-I18N-LOCALE", Locale.CHINESE);
        }
        else if (locale != null) {
            ActionContext.getContext().setLocale(locale);
            ActionContext.getContext().getSession().put("WW-TRANS-I18N-LOCALE", Locale.CHINESE);
        } else {
            ActionContext.getContext().setLocale(Locale.CHINESE);
            ActionContext.getContext().getSession().put("WW-TRANS-I18N-LOCALE", Locale.US);
        }
        return SUCCESS;
    }
}
